//
//  MeatSaleViewController.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/15.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatSaleListViewController.h"

#import "SeparateDetailsViewController.h"

#import "SeparatePlanCell.h"
#import "MeatPayView.h"

#import "ShelvesAlreadlyViewController.h"
#import "ShelvesNoViewController.h"


#import "XXPageTabView.h"


@interface MeatSaleListViewController ()

@property (nonatomic, strong) UIImageView *bgIcon;

@property (nonatomic, strong) UIView *batchEditPriceView;

@property (nonatomic, strong) MeatPayView *footer;

@property (nonatomic , strong) XXPageTabView *pageTabView;

@property (nonatomic , strong) ShelvesNoViewController *shopCollectionVC;

@property (nonatomic , strong) ShelvesAlreadlyViewController *qsCollectionVC;


@end

@implementation MeatSaleListViewController

#pragma mark - init method

- (void)setupUI {
    
    self.view.backgroundColor = KWhiteColor;
    
    [self.view insertSubview:self.bgIcon atIndex:0];
    
    
    {
        self.baseNavView.navTitleLabel.text = @"销售";
        self.baseNavView.navTitleLabel.textColor = KWhiteColor;
        self.baseNavView.line.hidden = YES;
        self.baseNavView.backgroundColor = KClearColor;
        
        [self.baseNavView.leftNavBtn setImage:[UIImage imageNamed:@"nav_white"] forState:UIControlStateNormal];
    }
    
    {
        [self.baseNavView.rightNavBtn setTitle:@"编辑" forState:UIControlStateNormal];
        [self.baseNavView.rightNavBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
        self.baseNavView.rightNavBtn.hidden = NO;
        self.baseNavView.rightNavBtn.isNeedAnimation = YES;
        
        __block BOOL selected = NO;
        @weakify(self);
        self.baseNavView.rightNavBtn.tapBlock = ^{
            @strongify(self);
            if (selected) {
                selected = NO;
                [self.baseNavView.rightNavBtn setTitle:@"编辑" forState:UIControlStateNormal];
                self.footer.alpha = 0;
            }else{
                selected = YES;
                [self.baseNavView.rightNavBtn setTitle:@"完成" forState:UIControlStateNormal];
                self.footer.alpha = 1;
            }
        };
    }

    [self.view addSubview:self.batchEditPriceView];

    [self addChildViewController:self.shopCollectionVC];
    [self addChildViewController:self.qsCollectionVC];
    [self.view addSubview:self.pageTabView];
    
    [self.view addSubview:self.footer];
    
}


- (void)setupLayout{
    
    {
        _bgIcon.size = CGSizeMake(KScreenWidth, TJ_StatusBarHeight + 177);
        _bgIcon.mj_x = _bgIcon.mj_y = 0;
    }
    
    {
        _batchEditPriceView.size = CGSizeMake(80, 20);
        _batchEditPriceView.mj_y = TJ_NavBarHeight + 10;
        _batchEditPriceView.mj_x = KScreenWidth - _batchEditPriceView.width;
    }

    [self.pageTabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(TJ_NavBarHeight);
    }];
    
    self.footer.mj_y = self.view.bottom - _footer.height;
}


- (void)initData {
    
}


#pragma mark - delegate
- (void)scrollToLast:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex-1];
}

- (void)scrollToNext:(id)sender {
    [self.pageTabView setSelectedTabIndexWithAnimation:self.pageTabView.selectedTabIndex+1];
}


#pragma mark - target action

- (void)transferManagerTapped {
    
}

#pragma mark - private method

#pragma mark - getter and setter

- (XXPageTabView *)pageTabView {
    if (!_pageTabView) {
        _pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"未上架",@"已上架"]];
        _pageTabView.delegate = self;
        _pageTabView.indicatorStyle = XXPageTabIndicatorStyleStretch;//跟随文本变化长度
        _pageTabView.titleStyle = XXPageTabTitleStyleGradient;//渐变
        _pageTabView.selectedTabIndex = 0;
        _pageTabView.tabSize = CGSizeMake(KScreenWidth - 200, 50);
        _pageTabView.separatorColor = [UIColor clearColor];
        _pageTabView.tabItemFont = mMediumFont(18);
        _pageTabView.indicatorHeight = 0;
        _pageTabView.bodyBounces = NO;
        _pageTabView.selectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.unSelectedColor = [UIColor colorWithHexString:@"#FFFFFF"];
        _pageTabView.tabBackgroundColor = [UIColor clearColor];
        _pageTabView.bodyBackgroundColor = [UIColor clearColor];
    }
    return _pageTabView;
}


- (MeatPayView *)footer{
    
    if (!_footer) {
        _footer = [[MeatPayView alloc] init];
        _footer.type = MeatPayType_SeparatePlan;
        _footer.alpha = 0;
        
        //全选Block
        @weakify(self);
        _footer.chooseCartBlock = ^(UIButton *btn) {
            
        };
        
        //预留
        _footer.clearCartBlock = ^{
            @strongify(self);
            [[AlertAction sharedInstance] showAlertWithTitle:nil message:@"您确定要全部预留吗？，一经预留不可更改" confirmBtnTitle:@"确定" confirmBlock:^{
                // [self clearLoginAccount];
            } cancelBlock:nil];
        };
        
        //销售
        _footer.deleteCartBlock = ^{
            
        };
    }
    return _footer;
}


- (UIView *)batchEditPriceView{
    
    if (!_batchEditPriceView) {
        _batchEditPriceView = [[UIView alloc] init];
        
        UIImage *image = [UIImage imageNamed:@"meat_ batch_edit_price"];
        _batchEditPriceView.layer.contents = (__bridge id)image.CGImage;
        
    }
    return _batchEditPriceView;
}



- (UIImageView *)bgIcon{
    
    if (!_bgIcon) {
        _bgIcon = [UIImageView new];
        _bgIcon.image = [UIImage imageNamed:@"meat_adopt_bg"];
    }
    return _bgIcon;
}


- (ShelvesNoViewController *)shopCollectionVC {
    if (!_shopCollectionVC) {
        _shopCollectionVC = [[ShelvesNoViewController alloc] init];
    }
    return _shopCollectionVC;
}


- (ShelvesAlreadlyViewController *)qsCollectionVC {
    if (!_qsCollectionVC) {
        _qsCollectionVC = [[ShelvesAlreadlyViewController alloc] init];
    }
    return _qsCollectionVC;
}


@end
